<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all" />
</head>

<body layadmin-themealias="default">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" pad15="">
                        <div class="layui-form" wid100="" lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" value="" maxlength="128" class="layui-input"
                                        placeholder="请输入" lay-verify="required" />
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">小编名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="author_name" value="" maxlength="32" class="layui-input"
                                        placeholder="请输入" lay-verify="required" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">资讯分类</label>
                                <div class="layui-input-inline">
                                    <select id="categoryid" name="category_id" lay-filter="category_id"
                                        lay-verify="required">
                                        <option value="">请选择</option>
                                        {volist name="category" id="vo"}
                                        <option value="{$vo.id}">{$vo.category_name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">是否为轮播图</label>
                                <div class="layui-input-block" id="isBannerArea">
                                    <input type="radio" value="1" name="is_banner" title="是" lay-filter="is_banner" />
                                    <input type="radio" value="0" name="is_banner" title="否" lay-filter="is_banner"
                                        checked />
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">图片</label>
                                <div class="layui-input-inline">
                                    <input name="img" id="LAY_iconImgSrcProps" placeholder="图片地址" value=""
                                    class="layui-input" lay-verify="" placeholder="可不填">
                                </div>
                                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                    <button type="button" class="layui-btn layui-btn-primary  LAY_iconImgUpload"
                                        lay-data="{idObjName: 'LAY_iconImgSrcProps'}">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <button class="layui-btn layui-btn-primary" layadmin-event="coverImgPreview"
                                        data-idname="LAY_iconImgSrcProps">查看图片
                                    </button>
                                </div>
                                <div class="layui-form-mid layui-word-aux" id="imgDesc"></div>
                            </div>


                            <div class="layui-form-item">
                                <label class="layui-form-label">热门推荐</label>
                                <div class="layui-input-block">
                                    <input type="radio" value="1" name="is_hot" title="是" />
                                    <input type="radio" value="0" name="is_hot" title="否" checked />
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">资讯状态</label>
                                <div class="layui-input-block">
                                    <input type="radio" value="1" name="status" title="上架" checked />
                                    <input type="radio" value="0" name="status" title="下架" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否自己创作</label>
                                <div class="layui-input-block">
                                    <input type="radio" value="1" name="own_creation" title="是" checked>
                                    <input type="radio" value="0" name="own_creation" title="否">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">内容</label>
                                <div class="layui-input-block" style="z-index: 1">
                                    <textarea placeholder="" class="layui-textarea" name="content" id="content"
                                        style="min-height: 500px; padding: 0; border: none"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="news-add">
                                        确认
                                    </button>
                                    <button class="layui-btn layui-btn-primary layuiadmin-btn-push" data-type="cancel">
                                        取消
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>
    <script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/ue/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/assets/ue/ueditor.all.min.js"></script>
    <script>
        layui.config({
            base: "/layuiadmin/"
            , version: "{:config('other.ui_version')}"
        }).extend({
            index: "lib/index", //主入口模块
        }).use(["index", "news", "form", "admin"], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            //事件
            var active = {
                cancel: function () {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                },
            };

            $(".layui-btn.layuiadmin-btn-push").on("click", function () {
                var type = $(this).data("type");
                active[type] ? active[type].call(this) : "";
            });


            var ue = UE.getEditor("content");

            form.on("submit(news-add)", function (obj) {
                var editContent = ue.getContent();
                layer.load();
                //提交
                admin.req({
                    url: "{:url('news/add_post')}",
                    data: {
                        title: obj.field.title,
                        author_name: obj.field.author_name,
                        category_id: obj.field.category_id,
                        status: obj.field.status,
                        is_banner: obj.field.is_banner,
                        img: obj.field.img,
                        is_hot: obj.field.is_hot,
                        content: editContent,
                        own_creation: obj.field.own_creation,
                    },
                    success: function (res) {
                        layer.closeAll("loading");
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 1 });
                            setTimeout(function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                parent.layui.table.reload("LAY-news-manage");
                            }, 1200);
                        }
                    },
                    complete: function () {
                        layer.closeAll("loading");
                    },
                });
                return false;
            });
        });
    </script>
</body>

</html>